package com.wsit.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wsit.mapper.OrderMapper;
import com.wsit.pojo.Order;
import com.wsit.pojo.OrderPage;
import com.wsit.pojo.PageBean;
import com.wsit.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;


    /**
     * 分页查询
     *
     * @param orderPage
     * @return
     */
    @Override
    public PageBean list(OrderPage orderPage) {
//        设置分页参数
        PageHelper.startPage(orderPage.getPage(), orderPage.getPageSize());
//      执行查询
        List<Order> orders = orderMapper.list(orderPage);
        Page<Order> page = (Page<Order>) orders;
        return  new PageBean(page.getTotal(),page.getResult());
    }

    /**
     * 添加订单
     *
     * @param order
     */
    @Override
    public void add(Order order) {
        order.setCreateTime(LocalDateTime.now());
         orderMapper.add(order);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public Order getById(Integer id) {
            return orderMapper.getById(id);

    }

    /**
     * 修改
     *
     * @param order
     */
    @Override
    public void update(Order order) {
        orderMapper.update(order);
    }
}
